# -*- coding: utf-8 -*-
# @Author  : pony.guan
# @Time    : 2021/12/3 17:29
# Description:

import pandas as pd
import json

with open('1') as f:
    data = json.loads(f.read())
    transport_tasks = data['transportTask']
    data1 = []
    data2 = []
    for t in transport_tasks:
        #TASK_2021120200000182
        code = t['code']

        if t.get('parentTaskCode', '')[5:13] == '20211221':
            if code.startswith('container'):
                data1.append(
                    {
                        'code': code,
                        'parentTaskCode': t['parentTaskCode'],
                        'intendedRobotCode': t['intendedRobotCode'],
                        'containerCode': t['containerCode']
                     }
                )

            elif code.startswith('return'):
                data2.append(
                    {
                        'code': code,
                        'parentTaskCode': t['parentTaskCode'],
                        'intendedRobotCode': t['intendedRobotCode'],
                        'containerCode': t['containerCode']
                    }
                )

    df1 = pd.DataFrame(data1)
    df2 = pd.DataFrame(data2)
    print(df1.head())
    print(df2.head())
    write = pd.ExcelWriter('1.xlsx')
    df1.to_excel(write, sheet_name='sheet1')
    df2.to_excel(write, sheet_name='sheet2')
    write.save()